package com.xyd.Service;

import com.xyd.Service.NewsService;
import com.xyd.bean.News;
import com.xyd.dao.NewsMapper;
import com.xyd.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class NewsService {
    SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
    NewsMapper newsMapper = sqlSession.getMapper(NewsMapper.class);

    public List<News> getPageNews() {
        return newsMapper.getPageNews();
    }


    public int insertNews(String title, String content) {
        return newsMapper.insertNews(title, content);
    }


    public int deleteNews(int id) {
        return newsMapper.deleteNews(id);
    }


    public News getNewsById(int id) {
        return newsMapper.getNewsById(id);
    }

    public int updateNews(News news) {
        return newsMapper.updateNews(news);
    }

    public int getTotalPage(int count, int pageSize) {
        return (count % pageSize == 0) ? (count / pageSize) : (count / pageSize) + 1;
    }

    public int getNewsCount() {
        return newsMapper.getNewsCount();
    }
}
